package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.ibeifeng.crm.bean.Classroom;
import com.ibeifeng.crm.dao.ClassroomDao;

@Repository
public class ClassroomDaoImpl implements ClassroomDao {
	Logger log = Logger.getLogger(ClassroomDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public List<Classroom> queryAll() {
		List<Classroom> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.ClassroomNS.queryAll");
		System.out.println(list);
		return list;
	}
	@Override
	public int add(Classroom classroom) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.ClassroomNS.insert", classroom);
		return result;
	}
	@Override
	public int update(Classroom classroom) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.ClassroomNS.update", classroom);
		return result;
	}
	@Override
	public int delete(Classroom classroom) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.ClassroomNS.delete", classroom);
		
		return result;
	}
	@Override
	public Classroom queryClassroom(Classroom classroom) {
		Classroom cr = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.ClassroomNS.findById", classroom);
		
		return cr;
	}
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.ClassroomNS.count");
		return count;
	}
	@Override
	public List<Classroom> findAllSplit(int pg, int pgSize) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		List<Classroom> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.ClassroomNS.findAllSplit",map);
		return list;
	}

}
